From de1885fe8fe279c95c2c2b101fad916958dadd4a Mon Sep 17 00:00:00 2001
From: Valentin Popov <valentin@popov.link>
Date: Thu, 12 Sep 2024 22:10:31 +0000
Subject: Added Pagination component

---
 src/pages/[...page].astro | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 src/pages/[...page].astro

(limited to 'src/pages/[...page].astro')

diff --git a/src/pages/[...page].astro b/src/pages/[...page].astro
new file mode 100644
index 0000000..23a5d51
--- /dev/null
+++ b/src/pages/[...page].astro
@@ -0,0 +1,30 @@
+---
+import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
+import { getCollection } from "astro:content";
+import Layout from "../layouts/BaseLayout.astro";
+import Pagination from "../components/Pagination.astro";
+import PostSummary from "../components/PostSummary.astro";
+
+export const getStaticPaths = (async ({ paginate }) => {
+	const posts = await getCollection("blog");
+	posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime());
+
+	return paginate(posts, {
+		pageSize: 5,
+	});
+}) satisfies GetStaticPaths;
+
+type Props = InferGetStaticPropsType<typeof getStaticPaths>;
+
+const { page } = Astro.props;
+---
+
+<Layout>
+	<section>
+		{page.data.map((post) => <PostSummary post={post} />)}
+	</section>
+
+	<section>
+		<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
+	</section>
+</Layout>
-- 
cgit v1.2.3